package com.p2p.controller.contentManagement;


import com.p2p.common.R;
import com.p2p.common.base.RespResult;
import com.p2p.common.view.CarouselVo;
import com.p2p.entity.Carousel;
import com.p2p.service.contentManagementService.CarouselService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping(value = "/carousel")
@Api(value = "轮播广告管理",tags = "轮播广告管理接口API")
public class CarouselController {
    @Autowired
    CarouselService carouselService;

    /**
     * 查询所有广告
     * @param carouselVo
     * @return
     */
    @RequestMapping(value = "/findAllCarousel",method = RequestMethod.POST)
    @ApiOperation(value = "显示所有的轮播广告",notes = "显示所有的轮播广告",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数默认第一页",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页显示记录数",paramType = "query",dataType = "String",required = true)
    })
    @ResponseBody
    public RespResult findAllCarousel(@RequestBody @ApiParam(name = "carouselVo",value = "查询条件",required = true)CarouselVo carouselVo){
        return carouselService.findAllCarousel(carouselVo);
    }

    /**
     * 通过id查询广告
     * @param id
     * @return
     */
    @RequestMapping(value = "/findCarouselById",method = RequestMethod.POST)
    @ApiOperation(value = "返回该轮播广告",notes = "返回该轮播广告",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "轮播广告id",paramType = "query",dataType = "String",required = true)
    })
    @ResponseBody
    public RespResult findCarouselById(Integer id){
        return carouselService.findCarouselById(id);
    }

    /**
     * 条件查询广告
     * @param carouselVo
     * @return
     */
    @RequestMapping(value = "/findCarouselByCondition",method = RequestMethod.POST)
    @ApiOperation(value = "条件返回",notes = "条件返回",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public RespResult findCarouselByCondition(@RequestBody @ApiParam(name = "carouselVo",value = "查询条件",required = true)CarouselVo carouselVo){
        return carouselService.findCarouselByCondition(carouselVo);
    }

    /**
     * 添加广告
     * @param carousel
     * @return
     */
    @RequestMapping(value = "/addCarousel",method = RequestMethod.POST)
    @ApiOperation(value = "添加轮播广告",notes = "添加轮播广告",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public RespResult addCarousel(@RequestBody @ApiParam(name = "carousel",value = "轮播实体",required = true)Carousel carousel){
        return carouselService.addCarousel(carousel);
    }

    /**
     * 添加图片
     * @param file
     * @param id
     * @param request
     * @return
     */
    @RequestMapping(value = "/addCarouselImg",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "添加轮播图片",notes = "添加轮播图片接口",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=400,message="参数错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "图片", paramType = "query", dataType = "String", required = true),
            @ApiImplicitParam(name = "id", value = "ID", paramType = "query", dataType = "String", required = true)
    })
    public RespResult addCarouselImg(@RequestParam("file") MultipartFile file, @RequestParam("id") Integer id, HttpServletRequest request){
        return carouselService.addCarouselImg(file,id,request);
    }

    /**
     * 删除广告
     * @param id
     * @return
     */
    @RequestMapping(value = "/deleteCarouselById",method = RequestMethod.POST)
    @ApiOperation(value = "删除一条轮播广告",notes = "删除一条轮播广告",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "轮播广告id",paramType = "query",dataType = "String",required = true)
    })
    @ResponseBody
    public RespResult deleteCarouselById(Integer id){
        return carouselService.deleteCarouselById(id);
    }

    /**
     * 修改轮播广告信息
     * @param carousel
     * @return
     */
    @RequestMapping(value = "/updateCarousel",method = RequestMethod.POST)
    @ApiOperation(value = "修改轮播广告",notes = "修改轮播广告",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public RespResult updateCarousel(@RequestBody @ApiParam(name = "carousel",value = "轮播实体",required = true)Carousel carousel){
        return carouselService.updateCarousel(carousel);
    }
}
